package com.chujian.system.sys.controller;


import com.chujian.framework.bean.IdName;
import com.chujian.framework.core.base.BaseController;
import com.chujian.framework.core.base.BaseService;
import com.chujian.framework.core.tsdata.Result;
import com.chujian.sys.entity.SysUser;
import com.chujian.sys.vo.SysUserSourceVo;
import com.chujian.system.sys.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 人员表控制层
 *
 * @author chujian
 * @since 2021-07-28
 */
@RequestMapping("/sysUser")
@RestController
@Slf4j
public class SysUserController extends BaseController<SysUser> {

    @Resource
    private SysUserService baseService;

    @Override
    public BaseService<SysUser> getBaseService() {
        return baseService;
    }

    /**
     * 重置密码
     *
     * @param idName idName
     * @return ok
     */
    @PostMapping("/resetPassword")
    public Result<?> resetPassword(@RequestBody IdName idName) {
        baseService.resetPassword(Long.parseLong("" + idName.getId()));
        return okRs();
    }

    /**
     * 获取用户，包含微信相关信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/getUserWithWxInfo")
    public Result<?> getUserWithWxInfo(@RequestParam("userId") Long userId) {
        SysUser sysUser = baseService.getUserWithWxInfo(userId);
        return okRs(sysUser);
    }

    /**
     * 保存同步数据
     */
    @PostMapping("/saveSync")
    public Result<?> saveSync(@RequestBody SysUserSourceVo sourceVo) {
        SysUser sysUser = baseService.saveSync(sourceVo);
        return okRs(sysUser);
    }

    @GetMapping("/getBySourceId")
    public Result<?> getBySourceId(@RequestParam("sourceId") String sourceId) {
        SysUser user = baseService.getBySourceId(sourceId);
        return okRs(user);
    }

}
